package com.example.springboot.controller;

import com.example.springboot.config.Shiro.security.SecurityUtil;
import com.example.springboot.model.form.Result;
import com.example.springboot.model.req.admin.MaterialReq;
import com.example.springboot.model.req.admin.WallHavenReq;
import com.example.springboot.model.sys.SysUser;
import com.example.springboot.model.vo.WallpaperVO;
import com.example.springboot.service.IndexService;
import com.example.springboot.service.admin.MaterialService;
import com.example.springboot.utils.IP.IpUtil;
import com.example.springboot.utils.IP.IpVo;
import com.example.springboot.utils.weather.WeatherInfo;
import com.example.springboot.utils.weather.WeatherUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

@RequestMapping("/index")
@RestController
public class IndexController {

    @Resource
    IndexService indexService;

    @Resource
    private MaterialService materialService;

    /**
     * @Description: 获取随机一张图片及素材
     */
    @PostMapping("/getRandomImg")
    public Result getRandomImg() {
        return indexService.getRandomImg();
    }

    /**
     * @Description: 获取随机10张图片及素材 或者 登录后的收藏图片
     */
    @PostMapping("/getTenRandomImg")
    public Result getTenRandomImg(WallHavenReq req) {
        return indexService.getTenRandomImg(req);
    }

    /**
     * @Description: 根据ip获取地址
     */
    @GetMapping("/getAddressById")
    public Result getAddressById(HttpServletRequest request) {
        String ipAddr = IpUtil.getIpAddr(request);
        IpVo ipVo = IpUtil.getIpVo(ipAddr);
        return Result.buildSuccess(ipVo);
    }

    /**
     * @Description: 根据城市获取天气
     */
    @PostMapping("/getWatherByCity")
    public Result getWatherByCity(String place) {
        WeatherInfo weatherData = WeatherUtils.getWeatherData(place);
        return Result.buildSuccess(weatherData.getData());
    }

    /**
     * @Description: 素材
     */
    @PostMapping("/material")
    public Result material(MaterialReq req) {
        return materialService.getPage(req);
    }

}
